package com.wilmer.aiUserChat.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wilmer.common.annotation.Log;
import com.wilmer.common.core.controller.BaseController;
import com.wilmer.common.core.domain.AjaxResult;
import com.wilmer.common.enums.BusinessType;
import com.wilmer.aiUserChat.domain.YwUserChat;
import com.wilmer.aiUserChat.service.IYwUserChatService;
import com.wilmer.common.utils.poi.ExcelUtil;
import com.wilmer.common.core.page.TableDataInfo;

/**
 * 聊天列表Controller
 *
 * @author hans
 * @date 2024-05-15
 */
@Api(tags = {"聊天列表接口"})
@RestController
@RequestMapping("/userchat/userchat")
public class YwUserChatController extends BaseController
{
    @Autowired
    private IYwUserChatService ywUserChatService;

    /**
     * 查询聊天列表列表
     */
    @ApiOperation("查询聊天列表列表")
    @PreAuthorize("@ss.hasPermi('userchat:userchat:list')")
    @GetMapping("/list")
    public TableDataInfo list(YwUserChat ywUserChat)
    {
        startPage();
        List<YwUserChat> list = ywUserChatService.selectYwUserChatList(ywUserChat);
        return getDataTable(list);
    }

    /**
     * 导出聊天列表列表
     */
    @PreAuthorize("@ss.hasPermi('userchat:userchat:export')")
    @Log(title = "聊天列表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, YwUserChat ywUserChat)
    {
        List<YwUserChat> list = ywUserChatService.selectYwUserChatList(ywUserChat);
        ExcelUtil<YwUserChat> util = new ExcelUtil<YwUserChat>(YwUserChat.class);
        util.exportExcel(response, list, "聊天列表数据");
    }

    /**
     * 获取聊天列表详细信息
     */
    @ApiOperation("获取聊天列表详细信息")
    @PreAuthorize("@ss.hasPermi('userchat:userchat:query')")
    @GetMapping(value = "/{chatId}")
    public AjaxResult getInfo(@PathVariable("chatId") String chatId)
    {
        return success(ywUserChatService.selectYwUserChatByChatId(chatId));
    }

    /**
     * 新增聊天列表
     */
    @ApiOperation("新增聊天列表")
    @PreAuthorize("@ss.hasPermi('userchat:userchat:add')")
    @Log(title = "聊天列表", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody YwUserChat ywUserChat)
    {
        return toAjax(ywUserChatService.insertYwUserChat(ywUserChat));
    }

    /**
     * 修改聊天列表
     */
    @ApiOperation("修改聊天列表")
    @PreAuthorize("@ss.hasPermi('userchat:userchat:edit')")
    @Log(title = "聊天列表", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody YwUserChat ywUserChat)
    {
        return toAjax(ywUserChatService.updateYwUserChat(ywUserChat));
    }

    /**
     * 删除聊天列表
     */
    @ApiOperation("删除聊天列表")
    @PreAuthorize("@ss.hasPermi('userchat:userchat:remove')")
    @Log(title = "聊天列表", businessType = BusinessType.DELETE)
	@DeleteMapping("/{chatIds}")
    public AjaxResult remove(@PathVariable String[] chatIds)
    {
        return toAjax(ywUserChatService.deleteYwUserChatByChatIds(chatIds));
    }
}
